package com.wu.controller;

import com.wu.pojo.Labels;
import com.wu.response.CommonReturnType;
import com.wu.service.LabelsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.wu.constant.Constant.DEFAULT_NULL_VALUE;

/**
 * @author: 吴磊
 * @program: blog
 * @create: 2021-04-27 21:21
 */
@RestController
@Api(tags = "文章标签")
public class LabelsController {

    @Autowired
    private LabelsService labelsService;

    /**
     * 获取所有的标签
     *
     * @return
     */
    @ApiOperation(value = "获取用户所有的标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "如果用户Id为空就说明是获取当前用户的全部标签", dataTypeClass = String.class)
    })
    @RequestMapping(value = "/getAllUserLabels", method = RequestMethod.POST)
    public CommonReturnType getAllUserLabels(@RequestParam(name = "userId", required = false, defaultValue = DEFAULT_NULL_VALUE) String userId) {
        List<Labels> allLabels = labelsService.getAllUserLabels(userId);
        return CommonReturnType.create(allLabels);
    }


    /**
     * 获取所有的标签
     *
     * @return
     */
    @ApiOperation(value = "获取所有的标签")
    @RequestMapping(value = "/getAllLabels", method = RequestMethod.POST)
    public CommonReturnType getALlLabels() {
        List<Labels> allLabels = labelsService.getAllLabels();
        return CommonReturnType.create(allLabels);
    }
}
